package stats;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicLong;

public class ConcurrentHashMapStatsService implements IStatsService
{
	private ConcurrentHashMap<String, AtomicLong>	stats;

	public ConcurrentHashMapStatsService ()
	{
		init();
	}

	private void init ( )
	{
		stats = new ConcurrentHashMap<String, AtomicLong>(5000, 1, 100);
	}

	public void notify ( String key )
	{
		AtomicLong value = stats.get(key);
		if (value == null)
		{
			value = stats.putIfAbsent(key, new AtomicLong(1));
		}
		if (value != null)
		{
			value.incrementAndGet();
		}
	}

	public Map<String, Number> getStats ( )
	{
		Map<String, AtomicLong> statsRef = stats;
		init();
		return new HashMap<String, Number>(statsRef);
	}

	public void stop ( )
	{}
}
